feat(pds): Remove bucket_name from R2 Binding - #201
Conversation
ascorbic
left a comment
There was a problem hiding this comment.
Thanks! I've checked this against wrangler's source and the config is valid: bucket_name is optional in the schema, provisioning is on by default and will create <worker>-blobs on first deploy, and both miniflare and the vite plugin handle the absent field. So for fresh scaffolds on current wrangler this works. A few things I want to talk through before merging though.
Blob orphaning on rename / recreate
With an explicit bucket_name, wrangler's provisioning reconnects to an existing bucket regardless of which script it's deploying. Without one, it only inherits bindings already on this script — so a renamed Worker, or one deleted and recreated, silently gets a brand new empty <newname>-blobs and every existing blob 404s. Wrangler mitigates this by writing the provisioned name back into wrangler.jsonc, but only when interactive; CI deploys never get it pinned.
What I'd prefer: keep the template as you have it, and have pds init write bucket_name: "<worker>-blobs" explicitly — it already patches name, routes and account_id via experimental_patchConfig in cli/utils/wrangler.ts, so it's one more field. That gives per-worker uniqueness and a pinned name, and it actually closes #107, which asks for a way to choose the name (this PR changes the default but still doesn't give a choice). Happy for that to be a follow-up if you'd rather keep this one small — but then please change "Closes #107" to "Related to".
Docs now contradict the template
These all still show bucket_name and tell people to pick a unique one:
docs/src/content/docs/reference/wrangler-config.md(~L112-120 and L153)docs/src/content/docs/guides/troubleshoot.md~L135 ("edit wrangler.jsonc" for a taken bucket name)docs/src/content/docs/reference/environment-variables.md~L103packages/pds/README.md~L71demos/pds/wrangler.jsonc(not wrong, just no longer mirrors the template)
Small
- Needs a changeset for
create-pds— something like "R2 bucket is now named after the Worker and created on first deploy". Commit scope should becreate-pdsrather thanpds. - The old config also auto-created
pds-blobsthrough the same provisioning path; the real behaviour change is the naming, not auto-creation. Worth saying that in the description. - Template pins
wrangler: ^4.54.0; anyone pinned below the version where provisioning became default-on getsBLOBS bindings must have a "bucket_name" field. Probably worth bumping the floor to something you've verified.
Closes #107.
When going through the creation flow for a new PDS,
wranglerwill now auto-create a bucket usingwrangler's Automatic Provisioning feature, which should prevent collisions between multiple PDSses, as you cannot have two Workers on an account with the same name.Example output from the deploy flow: